from bs4 import BeautifulSoup

html_doc = """
<html><head><title>The Dormouse's story</title></head>
<body>
<p class="title"><b>The Dormouse's story</b></p>

<p class="story">Once upon a time there were three little sisters; and their names were
<a href="http://example.com/elsie" class="sister" id="link1"><!--Elsie--></a>,
<a href="http://example.com/lacie" class="sister" id="link2">Lacie</a> and
<a href="http://example.com/tillie" class="sister" id="link3">Tillie</a>;
and they lived at the bottom of a well.</p>

<p class="story">...</p>

<input name="kaike" type="text">
"""

# 1.转解析类型
#  警告说明: 当前我们bs4 没有指定解析内库; 系统自动采用最高效的lxml
# bs4.BeautifulSoup
data = BeautifulSoup(html_doc, 'lxml')

# 2.解析
# title 标签选择器  点语法的这种 只能取出符合条件的第一个
result = data.title
result = data.p
result = data.a

# 标签里面的内容 ---string
result = data.title.string

# 标签的属性
result = data.a['id']

# 取出class属性是个列表 class允许是多个
result = data.a['class']

result = data.input['name']

result = data.a.content

print(data.prettify())  # 格式化输出
# print(result)
